home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
DIB.ZIP
/
BLIT4.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-12-05
|
3KB
|
142 lines
Program Blit4;
{ BitBlt and StretchBlt a 4 bit per pixel (16 color) bitmap }
{$R BLIT4.RES}
Uses
WinTypes,WinProcs,WObjects;
Const
id_FridgeBmp = 'FRIDGE';
Factor : Real = 2.0;
{---------------------------------------------------}
{ --- App/Win Object declarations --- }
Type
TBlitApp = Object(TApplication)
Procedure InitMainWindow; Virtual;
End;
PBlitWindow = ^BlitWindow;
BlitWindow = Object(TWindow)
hFridgeBmp : HBitmap;
Constructor Init(AParent: PWindowsObject; ATitle : PChar);
Destructor Done;
Virtual;
Procedure Paint(PaintDC : HDC; Var PaintInfo : TPaintStruct);
Virtual;
Procedure WMLButtonDown(Var Msg : TMessage);
Virtual wm_First + wm_LButtonDown;
Procedure WMRButtonDown(Var Msg : TMessage);
Virtual wm_First + wm_RButtonDown;
End;
{---------------------------------------------------}
{ --- App Methods --- }
Procedure TBlitApp.InitMainWindow;
Begin
MainWindow := New(PBlitWindow,Init(nil,'Blit 4-Bit Bitmap'));
End {InitMainWindow};
{---------------------------------------------------}
{ --- Window Methods --- }
Constructor BlitWindow.Init(AParent : PWindowsObject; ATitle : PChar);
Begin
TWindow.Init(AParent,ATitle);
hFridgeBmp := LoadBitmap(HInstance,id_FridgeBmp);
End {Init};
{---------------------------------------------------}
Destructor BlitWindow.Done;
Begin
DeleteObject(hFridgeBmp);
TWindow.Done;
End {Done};
{---------------------------------------------------}
Procedure BlitWindow.Paint(PaintDC : HDC; Var PaintInfo : TPaintStruct);
Var
OldBitmap : HBitmap;
MemDC : HDC;
BitmapSize : TPoint;
BmpInfo : TBitmap;
Begin
{ Create a memory DC and select our bmp into it }
MemDC := CreateCompatibleDC(PaintDC);
OldBitmap := SelectObject(MemDC,hFridgeBmp);
{ Get the bmp's size }
GetObject(hFridgeBmp,SizeOf(TBitmap),@BmpInfo);
BitmapSize.x := BmpInfo.bmWidth;
BitmapSize.y := BmpInfo.bmHeight;
{ Blit the bmp }
BitBlt(PaintDC,10,10,BitmapSize.x,BitmapSize.y,MemDC,0,0,srcCopy);
{ Stretch blit the bmp }
StretchBlt(PaintDC,10 + BitmapSize.x + 5,10,
Trunc(BitmapSize.x * Factor),Trunc(BitmapSize.y * Factor),
MemDC,
0,0,BitmapSize.x,BitmapSize.y,srcCopy);
{ Get rid of the memory DC }
SelectObject(MemDC,OldBitmap);
DeleteDC(MemDC);
End {Paint};
{---------------------------------------------------}
Procedure BlitWindow.WMLButtonDown(Var Msg : TMessage);
Begin
Factor := Factor + 0.5;
InvalidateRect(HWindow,Nil,False);
End {WMLButtonDown};
{---------------------------------------------------}
Procedure BlitWindow.WMRButtonDown(Var Msg : TMessage);
Begin
If Factor > 1.0
Then Begin
Factor := Factor - 0.5;
InvalidateRect(HWindow,Nil,True);
End;
End {WMRButtonDown};
{---------------------------------------------------}
{ --- Main --- }
Var
BlitApp : TBlitApp;
Begin
BlitApp.Init('Blit4App');
BlitApp.Run;
BlitApp.Done;
End.